package org.teamswift.crow.rbac.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.teamswift.crow.rbac.vo.CrowRoleVo;
import org.teamswift.crow.rest.annotation.I18N;
import org.teamswift.crow.rest.annotation.SystemGeneratedValue;
import org.teamswift.crow.rest.common.BaseCrowEntity;
import org.teamswift.crow.rest.common.ICrowEntity;

import javax.persistence.*;
import java.util.Set;

@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@Table(
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {
                        "organizationId", "name"
                })
        }
)
@EntityListeners(AuditingEntityListener.class)
public class CrowRole extends BaseCrowEntity<Integer, CrowRoleVo> implements ICrowEntity<Integer, CrowRoleVo> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @I18N("crow.id")
    private Integer id;

    @Override
    public Integer gtId() {
        return id;
    }

    @Column(nullable = false, length = 50)
    private String name;

    private String description;

    @SystemGeneratedValue
    private Integer organizationId;

    @Transient
    @SystemGeneratedValue
    private Set<CrowAuthority> authorities;

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

}
